<?php

	// +----------------------------------------------------------------------
	// | 附件控制器
	// | 主要用于下载模型的文件上传和下载.
	// +----------------------------------------------------------------------
	// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
	// +----------------------------------------------------------------------
	// | Author: 微尘 <yicmf@qq.com>
	// +----------------------------------------------------------------------

    namespace app\controller\file;

	use app\event\file\Attachment as AttachmentEvent;

	class Attachment extends Common
	{
		/* 文件上传 */
		public function upload()
		{
			if ($this->request->isPost()) {
				$attachment = $this->request->file('file');
				// 文件检查
				$image = new AttachmentEvent();
				$data = $image->upload($this->request->post(), $attachment, $this->user);
			} else {
				$data['code'] = 1;
				$data['message'] = 0;
			}
			return json($data);
		}

		/* 下载文件 */
		public function download($id = null)
		{
			if (empty($id) || !is_numeric($id)) {
				$this->error('参数错误！');
			}
			if (!$this->model->download($id)) {
				$this->error($this->model->getError());
			}
		}
	}
